import javax.swing.Timer;
import java.awt.event.*;

public abstract class BasicGate extends Gate implements ActionListener {

	private Timer timer = new Timer(super.getDelay(),this);
	private boolean temp_storage;
	
	public void inputChanged() {		
	
		if(!timer.isRunning()) {
			temp_storage = calculateValue();
			if(super.getOutputValue() != temp_storage)
				timer.start();
		}
			
	}

	public void actionPerformed(ActionEvent e) {
		timer.stop();
		outputChanged(temp_storage);
	}
	
	public abstract boolean calculateValue();	
	
}
